package com.csoa.community.requests;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;

import com.csoa.community.bean.AttachBean;
import com.csoa.community.net.ErrorMsg;
import com.csoa.community.utils.Json;
import com.csoa.community.utils.StringUtils;

public class TongzhiAttachRequest extends AbstractRequest {

	public List<AttachBean> mAttachs;
	public TongzhiAttachRequest(List<BasicNameValuePair> requestValues) {
		super(method_tongzhi_attach_list, requestValues);
	}

	

	@Override
	protected void parseRemaingInfo(String json) throws ErrorMsg, JSONException {
		if(!StringUtils.isEmpty(json)) {
			String strJson = "{value:"+json +"}";
			Json jsonAttachs = new Json(strJson);
			mAttachs = new ArrayList<AttachBean>();
			
			fillAttachList(jsonAttachs,mAttachs);
		}
		
	}
	
	
	private void fillAttachList(Json json, List<AttachBean> attachs) {
		Json[] jsons = json.getJsonArray("value");
		
		for (int i=0;i<jsons.length;i++) {
			AttachBean attach = new AttachBean();
			attach.AttachID = jsons[i].getString("AttachID");
			attach.FileName = jsons[i].getString("FileName");
			attach.FileExtend = jsons[i].getString("FileExtend");
			attachs.add(attach);
		}
		
	}
}
